#version 450 core

layout(location = 0) in vec3 aPostion;
layout(location = 1) in vec3 aNormal;
layout(location = 2) in vec2 aUv;
layout(location = 3) in uint aPackedData;


uniform mat4 uMVP;

out vec3 fragPos;
out vec2 fragUv;
out flat vec2 fragTexIdx;
out flat uint fragAnimSize;
out float fragLighting;

void main() {
    fragPos = aPostion;
    fragUv = aUv / 16.0f;

    uint xTexIdx = bitfieldExtract(aPackedData, 0, 6);
    uint yTexIdx = bitfieldExtract(aPackedData, 6, 6);
    fragTexIdx = vec2(xTexIdx, yTexIdx);

    uint animSize = bitfieldExtract(aPackedData, 12, 5);
    fragAnimSize = animSize + 1;

    uint occlusionLevel = bitfieldExtract(aPackedData, 17, 2);
    fragLighting = (0.75f + (0.08f * occlusionLevel));

    gl_Position = uMVP * vec4(fragPos, 1.0);
}